package com.qf.dao.impl;

import com.qf.dao.ShowGoodDao;
import com.qf.domain.Goods;
import com.qf.domain.User;
import com.qf.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class ShowGoodDaoImpl implements ShowGoodDao {
    private QueryRunner queryRunner = new QueryRunner(DataSourceUtil.getDataSource());
    @Override
    public List<User> slelect() {
        String sql = " select * from db_shopping.tb_user where role=1 ";
        try {
            return queryRunner.query(sql,new BeanListHandler<>(User.class));
        } catch (SQLException throwables) {
            throw new RuntimeException(throwables);
        }
    }

    @Override
    public List<Goods> slelectGoods(int id) {
        String sql = " select * from db_shopping.tb_goods where id=? ";
        try {
            return queryRunner.query(sql,new BeanListHandler<>(Goods.class),id);
        } catch (SQLException throwables) {
            throw new RuntimeException(throwables);
        }
    }

    @Override
    public List<Goods> selectByUAD(StringBuilder where1, List<Object> i) {
        String sql="select * from db_shopping.tb_goods "+where1;
        List<Goods> goodsList = null;
        try {
            goodsList = queryRunner.query(sql, new BeanListHandler<>(Goods.class),i.toArray());
        } catch (SQLException throwables) {
            throw new RuntimeException(throwables);
        }
        return goodsList;
    }


}
